#include <iostream>
#include <string>

using namespace std;

int N, L, A;
string tree, animal;
map<string, bool> features;

void readTree()
{
	scanf("%c", &c);
	{
	}

}

int main()
{
	scanf("%d\n", &N);	
	for (int ntest = 0; ntest < N; ntest++)
	{
		scanf("%d\n", &L);
		tree == "";
		for (int nline = 0; nline < L; nline++)
		{
			string line;
			getline(cin, line);
			tree += line;
		}

		scanf("%d\n", &A);
		for (int i = 0; i < A; i++)
		{
			string line;
			cin >> animal >> n;
			for (int j = 0; j < n; j++)
			{
				string feature;
				cin >> feature;
				features[feature] = true;
			}
			getline(cin, line);
		}



	}
}
